import {Store} from 'iflux2';
import {message} from 'antd';

import GoodsSetActor from './actor/goods-set';
import {getSetting, handleSetting} from './webapi';

export default class AppStore extends Store{
  bindActor() {
    return [
      new GoodsSetActor
    ]
  }
  init = async () => {
    const {data} = await getSetting();
    this.dispatch('init-setting', data)
  }
  onSetting = (data) => {
    this.dispatch('set-active', data);
  }
  onSave = async () => {
    const  {status, defaultContent} = this.state().toJS().defaultComment
    if (status == 1) {
        if (!defaultContent || defaultContent.length < 10 || defaultContent.length > 50) {
          message.error("默认评价内容限制10-50字符")
           return;
        }
    }
    const {err} = await handleSetting(this.state().toJS());
    if(!err) {
      message.success('保存成功')
    } else {
        message.error(err)
    }
  }
}